package com.mingshine.cloud.controller;

import com.mingshine.cloud.entity.User;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags="用户接口") //相当于类注释
public class UserController {

    @GetMapping("/hello")
    public String hello(){
        return "heeo swagger测试";
    }

    @GetMapping("/user")
    @ApiOperation("根据用户id查询") //相当于方法注释
    @ApiImplicitParam(name = "查询id",value = "用户id",defaultValue = "99") // 相当方法的参数注释
    public User getUserId(Integer id){
        User user = new User();
        user.setId(id);
        return user;
    }
    @PutMapping("/user")
    @ApiOperation("根据id更新用户名")
    @ApiImplicitParams({ //这注解能写多个参数注释
            @ApiImplicitParam(name = "id",value = "用户id",defaultValue = "99"),
            @ApiImplicitParam(name = "username",value="用户名",defaultValue = "默认值")
    })
    public User updateUsernameById(String username,Integer id){
        User user = new User();
        user.setId(id);
        user.setUsername(username);
        return user;
    }
    @DeleteMapping("/user{id}")
    @ApiOperation("根据id删除用户")
    @ApiImplicitParam(name = "id",value = "用户id",defaultValue = "99")
    public void deleteUserById(@PathVariable  Integer id){
        System.out.println(id);
    }
    @PostMapping("/user")
    @ApiOperation("根据对象添加用户")
    public User addUser(@RequestBody  User user){
        return user;
    }

}

